package com.valley.dream.tihai.view.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.valley.dream.tihai.R;
import com.valley.dream.tihai.model.dto.InitProblemBO;
import com.valley.dream.tihai.model.dto.SelectProblemByRecommendVO;

import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


public class RecommendRVAdapter extends RecyclerView.Adapter<RecommendRVAdapter.ViewHolder> {

    private Context context;
    private List<SelectProblemByRecommendVO> problemBOS;

    public RecommendRVAdapter() {
    }

    public RecommendRVAdapter(Context context, List<SelectProblemByRecommendVO> problemBOS) {
        this.context = context;
        this.problemBOS = problemBOS;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LinearLayout.inflate(context, R.layout.fragment_recommend_item, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.nickname.setText("用户名："+problemBOS.get(position).getUsername());
        holder.title.setText("标题："+problemBOS.get(position).getTitle());
        holder.choiceA.setText("选项A："+problemBOS.get(position).getChoiceA());
        holder.choiceB.setText("选项B："+problemBOS.get(position).getChoiceB());
        holder.choiceC.setText("选项C："+problemBOS.get(position).getChoiceC());
        holder.choiceD.setText("选项D："+problemBOS.get(position).getChoiceD());
        holder.typeName.setText("类型名："+problemBOS.get(position).getTypeName());
    }

    @Override
    public int getItemCount() {
        return problemBOS.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        public TextView nickname, title, choiceA, choiceB, choiceC, choiceD, typeName;

        public ViewHolder(@NonNull View root) {
            super(root);
            nickname = root.findViewById(R.id.recommend_text_nickname);
            title = root.findViewById(R.id.recommend_text_title);
            choiceA = root.findViewById(R.id.recommend_text_choiceA);
            choiceB = root.findViewById(R.id.recommend_text_choiceB);
            choiceC = root.findViewById(R.id.recommend_text_choiceC);
            choiceD = root.findViewById(R.id.recommend_text_choiceD);
            typeName = root.findViewById(R.id.recommend_text_typeName);
        }
    }
}
